package com.runmi.webchat.aftersale.dbcore.dao;

import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Repository;

import com.runmi.webchat.aftersale.dbcore.entity.UserOpenId;
import com.runmi.webchat.aftersale.dbcore.mapper.UserOpenIdMapper;

@Repository
public class UserOpenIdDao {
	@Autowired
	private UserOpenIdMapper userOpenIdMapper;
	
	/**
	 * 获取用户信息
	 * @param openId
	 * @return
	 */
	public UserOpenId getUserInfoByOpenId(String openId){
		UserOpenId record=new UserOpenId();
		record.setDelFlag((byte)0);
		record.setOpenId(openId);
		List<UserOpenId> items= userOpenIdMapper.select(record);
		if(null!=items && items.size()>0){
			return items.get(0);
		}else{
			return null;
		}
	}
	
	/**
	 * 获取有效的用户信息
	 * @param openId
	 * @return
	 */
	public UserOpenId getUserByOpenId(String openId){
		UserOpenId record=new UserOpenId();
		record.setDelFlag((byte)0);
		record.setOpenId(openId);
		record.setStatus((byte)1);
		List<UserOpenId> items= userOpenIdMapper.select(record);
		if(null!=items && items.size()>0){
			return items.get(0);
		}else{
			return null;
		}
	}
	/**
	 * 获取店员信息
	 * @param openId
	 * @return
	 */
	public UserOpenId getShopUserByOpenId(String openId){
		UserOpenId record=new UserOpenId();
		record.setDelFlag((byte)0);
		record.setOpenId(openId);
		record.setStatus((byte)1);
		record.setUserType((byte)1);
		List<UserOpenId> items= userOpenIdMapper.select(record);
		if(null!=items && items.size()>0){
			return items.get(0);
		}else{
			return null;
		}
	}
}
